<%--
  Created by IntelliJ IDEA.
  User: qingx
  Date: 2018/12/27
  Time: 18:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <title>Title</title>
    <%@ include file="../base/top.jsp" %>
    <style>
        #result_admin{
            width: 90%;
            margin: auto;
            margin-top: 20px;
            padding: 20px;
            box-shadow: 0px 0px 3px #888888 ;
            border-radius: 5px;
            background-color: #FFFFFF;
        }
    </style>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">
                        <%--datatable--%>
                        <div id="result_admin">
                            <table id="data-table" width="100%" class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th>
                                        全选<input type="checkbox" id="check-all"/>
                                    </th>
                                    <th>序号</th>
                                    <th>授课名称</th>
                                    <th>项目名称</th>
                                    <th>组长</th>
                                    <th>组员</th>
                                    <th>创建时间</th>
                                    <th>修改时间</th>
                                    <th>指导老师</th>
                                    <th>部署地址</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                            <button class="btn btn-success" id="add" onclick="addProject()">新增</button>
                            <button class="btn btn-success" id="download" type="button">下载</button>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->

</div>
<%@ include file="../base/foot.jsp" %>
<script>
    var table = null;
    var columnsData =  [
        {
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return "<input type=\"checkbox\"/>";
            }
        },
        {
            bSortable : false,
            data: null,
            width : "40px",
            className: 'text-center whiteSpace',
            render:function(data,type,row,meta) {
                return meta.row + 1 +
                    meta.settings._iDisplayStart;
            }
        },
        {'data': 'teachCourseInfo.teachCourseName'},
        {'data': 'projectName'},
        {'data': 'teamLeader.stuName',
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }
        },
        {'data': 'teammates',
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }
        },
        {'data': 'projectCreateTime',
            bSortable : true,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return  moment(data).format("YYYY-MM-DD");
            }
        },
        {'data': 'projectUpdateTime',
            bSortable : true,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return moment(data).format("YYYY-MM-DD");;
            }
        },
        {'data': 'teacherInfo.teaName'},
        {'data': 'projectDeploymentAddress',
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }
        },
        {
            bSortable : false,
            className : "text-center",
            width : "100px",
            render : function(data, type, row, meta) {
                var id = '"' + row.id + '"';
                var html = "";
                html += "<a href='javascript:void(0);' onclick='edit(this)' class='up btn btn-primary btn-xs'><i class='fa fa-arrow-up'></i> Edit</a>";
                //  html += "<a href='javascript:void(0);'   onclick='deleteThisRowPapser("+ id + ")'  class='down btn btn-danger btn-xs'><i class='fa fa-arrow-down'></i> Delete</a>";
                return html;
            }
        }
    ];
    var dataBaseFiled =  [
        {'column3': 'projectName'},
        {'column6': 'projectCreateTime'},
        {'column7': 'projectUpdateTime'}
    ];
    var url='project/getList';
    var paramter = null;
    $(document).ready(function() {
        table = $('#data-table').DataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION,{

            columns:columnsData,
            ajax: function (data,callback) {
                ajax(data,callback,dataBaseFiled,url,paramter);
            },
            order:[[ 2, "asc" ]]
        }));
    });


    function addProject() {
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="录入项目";
        diag.URL = "<%=basePath%>project/toAddProject";
        diag.Width = 630;
        diag.Height = 485;
        diag.CancelEvent = function(){ //关闭事件
            // alert(diag.innerFrame.contentWindow.document.getElementById('success').value);
            if("true" == diag.innerFrame.contentWindow.document.getElementById('success').value){
                operateSuccess();
            }
            diag.close();
        };
        diag.show();

    }

    function edit(button) {
        var projectInfo =  getClickedRowValue(button);
        console.log(projectInfo);
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="修改项目";
        diag.URL = '<%=basePath%>project/toEditProject?projectId='+projectInfo["projectId"];
        diag.Width = 630;
        diag.Height = 485;
        diag.CancelEvent = function(){ //关闭事件
            var success = diag.innerFrame.contentWindow.document.getElementById('success').value;
            var msg = diag.innerFrame.contentWindow.document.getElementById('msg').value;
            diag.close();
            if("true" == success ){
                operateSuccess(msg);
            }else if("false" == success){
                operateError(msg);
            }
        };
        diag.show();
    }

    function operateSuccess() {
        //弹提示框
        prompt_alert('success',"成功");
        //刷新表格数据
        reloadDataTable();
    }

    $("#download").click(function (){
        var type ;
        var form = new FormData();
        var projectIds = new Array();
        var checked = getAllCheckedRowValue();
        for (var index = 0; index < checked.length; index++) {
            prompt_alert('success',checked[index].projectId,0);
            projectIds.push(checked[index].projectId);
        }
        form.append( "projectIds",projectIds);
        bootbox.confirm({
            message: "请选择下载内容：",
            backdrop: false,
            buttons: {
                confirm: {
                    label:"下载全部",
                    className: 'left btn-success'
                },
                cancel: {
                    label: "仅下载最新",
                    className: 'right btn-danger'
                }
            },
            callback: function (result) {
                if(result==true){
                    //下载全部
                    type = 1;
                }else{
                    type = 0;
                }
                form.append( "type",type);
                var assignmentIds = new Array();
                $.ajax({
                    type:"POST",
                    url:"assignment/showProjectAssignment",
                    data:form,
                    dataType:"json",
                    processData:false,
                    contentType:false,
                    success:function (data) {
                        if(data["success"]==true){
                            //prompt_alert("error","!!!");
                            for (var index = 0; index < data.data.length; index++) {
                                download(data.data[index].assignmentName+data.data[index].fileType, data.data[index].assignmentAddress);
                                assignmentIds.push(checked[index].assignmentId);
                            }
                            /*$.ajax({
                                type:"POST",
                                url:"assignment/editAssignmentState",
                                data:assignmentIds,
                                dataType:"json",
                                success:function (data) {
                                    if(data["success"]==true){
                                        prompt_alert('success',"下载成功",0);
                                        reloadDataTable();
                                    }else{
                                        prompt_alert('error',"下载失败",0);
                                    }
                                },
                                error:function (){
                                    prompt_alert('error',"请检查网络连接...",0);
                                },
                            });*/
                        }else{
                            prompt_alert('error',"查询失败",0);
                        }
                    },
                    error:function (){
                        prompt_alert('error',"请检查网络连接...",0);
                    },
                });

            }
        });

    });
</script>

</body>
</html>
